layui.define(['table', 'form'], function(exports){
	var $ = layui.$,table = layui.table,form = layui.form;

	table.render({
	    elem: '#LAY-table'
	    ,url: layui.setter.webRoot + '/market/order/list.data'
	    ,method: 'post'
	    ,parseData: function (res) {
	        return {
	            "code": res.code,
	            "msg": res.msg,
	            "count": res.body.total,
	            "data": res.body.data
	        };
	    }
	    ,response: {statusCode: 200}
	    ,cols: [[
	      {field: 'tradeNo', title: '订单号'}
	      ,{field: 'goodsName', title: '商品名称'}
	      ,{field: 'projectId', title: '来源',templet:function(record){
				if(record.projectName){
					return record.projectName + '('+record.projectId+')'
				}else{
					return record.projectId;
				}
			}}
	      ,{field: 'goodsMoneyStr', title: '单价(元)'}
		  ,{field: 'goodsCount', title: '商品数量'}
	      ,{field: 'payMoneyStr', title: '支付(元)'}
			,{field: 'supplyStateName', title: '供货状态'}
	      ,{field: 'stateName', title: '状态',templet:function(record){
				if(record.state == 2){
					return '<span class="layui-badge layui-bg-green">'+record.stateName+'</span>';
				}else if(record.state == 3 || record.state == 5 ){
					return '<span class="layui-badge layui-bg-blue">'+record.stateName+'</span>';
				}else if(record.state == 4){
					return '<span class="layui-badge layui-bg-orange">'+record.stateName+'</span>';
				}else if(record.state == 7 || record.state == 8){
					return '<span class="layui-badge layui-bg-gray">'+record.stateName+'</span>';
				}else {
					return record.stateName;
				}
			}}
	      ,{field: 'createDate', title: '创建时间'}
	      ,{title: '操作', width: 100, align:'center', fixed: 'right', toolbar: '#table-toolbar'}
	    ]]
	    ,page: true
	    ,limit: 30
	    ,height: 'full-220'
	    ,text: '对不起，加载出现异常！'
  	});

	var active = {
		info: function(obj){
			layer.open({
				type: 2
				,title: '业务订单详情'
				,content: layui.setter.webRoot + '/market/order/info.html?tradeNo='+obj.data.tradeNo
				,maxmin: true
				,area: ['90%', '90%']
				,btn: [ '取消']
				,end:function (){
					table.reload('LAY-table');
				}
			});
		}
	}

	//监听搜索
	form.on('submit(LAY-search)', function(data){
		var field = data.field;
		//执行重载
		table.reload('LAY-table', {
			where: field
		});
	});

	table.on('tool(LAY-table)', function(obj){
		var type = obj.event ;
		active[type] ? active[type].call(this,obj) : '';
	});

	exports('market_business_order_list', {})
});